// pages/ArticleDetail/ArticleDetail.js
var cache = require("../../common/Cache.js").cache;
var dataFilter = require("../../common/DataFilter.js").dataFilter;
var wxParse = require("../../plugs/wxParse/wxParse.js");

const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imagesContent: [],
    textContent: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(options.id )
    // console.log(app.macauweburl.webApiUrl + "AppArticle/GetDetail")

    var id = options.id;
    console.log("987",id)
    var that = this;
    wx.request({
      // url: app.macauweburl.webApiUrl + "Article/GetArticleDetail",
      // url: "http://10.68.2.9/CenMacauCMS2/api/Article/GetArticleDetail",
      url: app.macauweburl.webApiUrl + "Article/GetArticleDetail",
      // data: {
      //   code: id,
      // },
      data: {
        Code: id,
      },
      success(res) {
        // console.log('==================================');
        var ArContent = res.data.ArContent.replace(/img {max-width:100%;}/, "");
        that.setData({
          // imagesContent: [res.data.Images[0].split(";")[1]],
          imagesContent: res.data.Images,
          textContent: res.data.ArContent
        })
        // wxParse.wxParse('article', 'html', res.data.ArContent, that, 5);

        // console.log("标题是：", res.data.Title);
        wx.setNavigationBarTitle({
          title: res.data.Title
        })

      }
    })



    /*读取对应文章详情*/
    /* cache.get("allArticle",function(result){
       var article=result;
       var articleDetail = dataFilter.getFilter("ID",id,article,1);
       app.console.log("Id:"+id);
       if(articleDetail==undefined){
         return;
       }
       articleDetail.ArContent = articleDetail.ArContent.replace(/img {max-width:100%;}/,"");
 
       wxParse.wxParse('article', 'html', articleDetail.ArContent, that, 5);
 
       console.log("标题是：", articleDetail.Title);
       wx.setNavigationBarTitle({
         title: articleDetail.Title
       })   
       //app.console.log(articleDetail);
     });*/


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  // 预览图片
  showImg (event) {
    let index = event.currentTarget.dataset.index;
    // console.log(index);
    wx.previewImage({
      current: this.data.imagesContent[index], // 当前显示图片
      urls: this.data.imagesContent // 需要预览的图片列表
    })
  }
})